﻿
@{
    ViewBag.Title = "合并科室维护";
}

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="科室编码" name="DeptCode" id="DeptCode">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="科室名称" name="DeptName" id="DeptName">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-dept-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>

                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <div class="layui-row layui-col-space5">
                <div class="layui-col-xs12">
                    <table id="LAY-dept-list" lay-filter="LAY-dept-list"></table>
                    <script type="text/html" id="table-toolbar">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
                            <button class="layui-btn layui-btn-sm" lay-event="export">导出</button>
                        </div>
                    </script>
                    <script type="text/html" id="barBtn">
                        <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
                        <button class="layui-btn layui-btn-sm" lay-event="del">删除</button>
                        <button class="layui-btn layui-btn-sm" lay-event="dept">科室对照</button>
                    </script>
                </div>
            </div>
            
        </div>
    </div>
</div>
<script type="text/javascript">
    var transfer, admin, table;
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'admin'], function () {
        var form = layui.form
            , $ = layui.$;
        admin = layui.admin;
        table = layui.table
        transfer = layui.transfer;
        //数据绑定
        table.render({
            elem: '#LAY-dept-list'
            , url: '/DeptMergeInfo/GetList' //模拟接口
            , toolbar: '#table-toolbar'
            , method: 'post'
            , cols: [[
                { field: 'DeptCode', title: '科室编码', width: 120 }
                , { field: 'DeptName', title: '科室名称', width: 200 }
                , { field: 'SpellCode', title: '拼音码', width: 100 }
                , { field: 'ValidFlag', title: '是否有效', width: 100 }
                //, { field: 'DeptType', title: '住院类别', width: 100 }
                , { field: 'HospitalAreaName', title: '院区', width: 100 }
                , { field: 'OperCode', title: '操作代码', width: 120 }
                , { field: 'OperDate', title: '操作时间', width: 120 }
                , { field: 'right', title: '操作', width: 240, align: 'center', fixed: 'right', toolbar: '#barBtn' }
            ]]
            , page: true
            , limit: 10
            , limits: [10, 15, 20, 25, 30]
            , text: { none: '暂无数据' }
        });
        initTableBtn(table);
        //头工具栏事件
        table.on('toolbar(LAY-dept-list)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2
                        , title: '添加科室'
                        , content: '/DeptMergeInfo/Add?deptCode='
                        , area: ["800px", "500px"]
                        , maxmin: true
                    });
                    break;
                case 'export':
                    var form = document.createElement('form');
                    form.action = '/DeptMergeInfo/export';
                    form.method = 'post';
                    $(document.body).append(form);
                    form.submit();
            };
        });
    
        //监听行工具事件
        table.on('tool(LAY-dept-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    admin.req({
                        url: '/DeptMergeInfo/DelByCode' //实际使用请改成服务端真实接口
                        , method: 'post'
                        , data: "deptCode=" + data.DeptCode
                        , done: function (res) {
                            layer.msg(res.msg, {
                                offset: '50px'
                                , icon: 1
                                , time: 2000
                            }, function () {
                                table.reload('LAY-dept-list'); //重载表格
                            });
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2
                    , title: '编辑科室'
                    , content: '/DeptMergeInfo/Add?deptCode=' + data.DeptCode
                    , area: ["800px", "600px"]
                    , maxmin: true
                });
            }
            else if (obj.event === 'dept') {
                layer.open({
                    type: 2
                    , title: '科室对照'
                    , content: '/DeptMergeInfo/DeptCompare?deptCode=' + data.DeptCode
                    , area: ["800px", "600px"]
                    , maxmin: true
                });
            }
        });
        //监听搜索
        form.on('submit(LAY-dept-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('LAY-dept-list', {
                where: field,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });
    });
</script>
